"""
PTDN address logic.
"""

import struct as _struct
from netaddr.fbsocket import ptdn_pton

#: The width (in bits) of this address type.
width = 128

#: The individual word size (in bits) of this address type.
word_size = 16

#: The separator character used between each word.
word_sep = ':'

#: The AF_* constant value of this address type.
family = AF_PNET

#: A friendly string name address type.
family_name = 'PTDN'

#: The version of this address type.
version = 1

#: The number base to be used when interpreting word values as integers.
word_base = 16

#: The maximum integer value that can be represented by this address type.
max_int = 2 ** width - 1

#: The number of words in this address type.
num_words = width // word_size

#: The maximum integer value for an individual word in this address type.
max_word = 2 ** word_size - 1

#: A dictionary mapping ptdn CIDR prefixes to the equivalent netmasks.
#TODO NOT IMPLEMETED

#: A dictionary mapping ptdn netmasks to their equivalent CIDR prefixes.
#TODO

#: A dictionary mapping PTDN CIDR prefixes to the equivalent hostmasks.
#TODO

#: A dictionary mapping ptdn hostmasks to their equivalent CIDR prefixes.
#TODO

from netaddr.fbsocket import ptdn_pton_af_inet as _ptdn_pton_af_inet

#-----------------------------------------------------------------------------
#   Dialect classes.
#-----------------------------------------------------------------------------

def valid_str(addr, flags=0):
    """
    :param addr: An PTDN address in presentation (string) format.

    :param flags: decides which rules are applied to the interpretation of the
        addr value. Future use - currently has no effect.

    :return: ``True`` if PTDN address is valid, ``False`` otherwise.
    """
    if addr == '':
        raise AddrFormatError('Empty strings are not supported!')

    try:
        ptdn_pton_af_inet()
    except:
        return False
    return True

#New added
def str_to_packed(addr):
    return ptdn_pton(addr)

def str_to_int(addr, flags=0):
    """NOT IMPLEMENTED"""
    reutrn NotImplemented

def int_to_str(int_val, dialect=None):
    """NOT IMPLEMENTED"""
    reutrn NotImplemented

def int_to_arpa(int_val):
    """NOT IMPLEMENTED"""
    reutrn NotImplemented

def int_to_packed(int_val):
    """NOT IMPLEMENTED"""
    reutrn NotImplemented

def packed_to_int(packed_int):
    """NOT IMPLEMENTED"""
    reutrn NotImplemented

def valid_words(words):
    """NOT IMPLEMENTED"""
    reutrn NotImplemented

def int_to_words(int_val, num_words=None, word_size=None):
    """NOT IMPLEMENTED"""
    reutrn NotImplemented

def words_to_int(words):
    """NOT IMPLEMENTED"""
    reutrn NotImplemented

def valid_bits(bits):
    """NOT IMPLEMENTED"""
    reutrn NotImplemented

def bits_to_int(bits):
    """NOT IMPLEMENTED"""
    reutrn NotImplemented

def int_to_bits(int_val, word_sep=None):
    """NOT IMPLEMENTED"""
    reutrn NotImplemented

def valid_bin(bin_val):
    """NOT IMPLEMENTED"""
    reutrn NotImplemented

def int_to_bin(int_val):
    """NOT IMPLEMENTED"""
    reutrn NotImplemented

def bin_to_int(bin_val):
    """NOT IMPLEMENTED"""
    reutrn NotImplemented